package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.assemble.BusinessAssembler;
import com.tarena.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.common.basic.converter.AdminConverter;
import com.tarena.lbs.pojo.basic.bo.BusinessBO;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import com.tarena.lbs.pojo.basic.vo.DictItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "商家模块")
@Slf4j
@RestController
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @Autowired
    private BusinessAssembler businessAssembler;
    @Autowired
    private AdminConverter adminConverter;

    @ApiOperation("获取商家分页信息")
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery businessQuery){
        log.debug("获取商家分页信息参数BusinessQuery :{}",businessQuery);
        businessQuery.setPageNo(1);
        businessQuery.setPageSize(10);
        BasePageList<BusinessBO> boList= businessService.pageList(businessQuery);
        PageResult<BusinessVO> pageVOs = businessAssembler.assemblePageResultVO(boList,businessQuery);
        return new Result<>(pageVOs);
    }


     //查询商家行业分类
    @ApiOperation("查询商家行业分类")
    @GetMapping("/admin/basic/dictItem/info/getlistAll/{dictId}")
    public Result<List<DictItemVO>> businessTypes(){
        log.debug("查询商家行业分类....");
        return new Result<>(businessAssembler.assembleStaticBusinessTypes());
    }

    @ApiOperation("新增商家信息")
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> businessSave(@RequestBody BusinessParam businessParam) throws BusinessException{
        log.debug("新增商家信息 BusinessParam:{}",businessParam);
        businessService.businessSave(businessParam);
        return Result.success();
    }
}
